package main

func isAlphaNumeric(c byte) bool {
	if c >= 'a' && c <= 'z' {
		return true
	}
	if c >= 'A' && c <= 'Z' {
		return true
	}
	if c >= '0' && c <= '9' {
		return true
	}
	return false

}

func toLower(c byte) byte {
	if c >= 'A' && c <= 'Z' {
		return c + 'a' - 'A'
	}
	return c
}

func isPalindrome(s string) bool {
	if s == "" {
		return true
	}
	i := 0
	j := len(s) - 1
	for i < j {
		a := s[i]
		for !isAlphaNumeric(a) && i < j {
			i++
			a = s[i]
		}
		b := s[j]
		for !isAlphaNumeric(b) && i < j {
			j--
			b = s[j]
		}
		if toLower(a) != toLower(b) {
			return false
		}
		i++
		j--
	}
	return true
}

func main() {
	println(isPalindrome("A man, a plan, a canal: Panama"))
	println(isPalindrome("race a car"))
	println(isPalindrome("a"))
	println(isPalindrome(""))
}
